package com.inffem.dbseite;

import com.inffem.dbif.Book;
import com.inffem.dbif.Kategorie;
import com.inffem.dbif.Rating;

public class BookImpl implements Book {
	
	private String titel;
	private String autor;
	private Kategorie kategorie;
	private Rating rating;
	private String nachname;
	private String vorname;

	public String getNachname() {
		return nachname;
	}

	public void setNachname(String nachname) {
		this.nachname = nachname;
	}

	public String getVorname() {
		return vorname;
	}

	public void setVorname(String vorname) {
		this.vorname = vorname;
	}
	
	BookImpl(String autor, String nachname, String vorname, String titel, Kategorie kategorie, Rating rating) {
		this.titel = titel;
		this.autor = autor;
		this.kategorie = kategorie;
		this.rating = rating;
		this.nachname=nachname;
		this.vorname=vorname;
	}
	

	public BookImpl(String autor, String titel, Kategorie kategorie, Rating rating) {
		this(autor, "", "",titel,kategorie,rating);
	}
	
	public BookImpl(String nachname, String vorname, String titel) {
		this("",nachname,vorname,titel,Kategorie.GENERAL,Rating.NULL);
	}
	
	/* (non-Javadoc)
	 * @see com.inffem.dbif.BookIf#getTitel()
	 */
	public String getTitel() {
		return titel;
	}
	/* (non-Javadoc)
	 * @see com.inffem.dbif.BookIf#setTitel(java.lang.String)
	 */
	public void setTitel(String titel) {
		this.titel = titel;
	}
	/* (non-Javadoc)
	 * @see com.inffem.dbif.BookIf#getAutor()
	 */
	public String getAutor() {
		return autor;
	}
	/* (non-Javadoc)
	 * @see com.inffem.dbif.BookIf#setAutor(java.lang.String)
	 */
	public void setAutor(String autor) {
		this.autor = autor;
	}
	/* (non-Javadoc)
	 * @see com.inffem.dbif.BookIf#getKategorie()
	 */
	public Kategorie getKategorie() {
		return kategorie;
	}
	/* (non-Javadoc)
	 * @see com.inffem.dbif.BookIf#setKategorie(com.inffem.dbif.Kategorie)
	 */
	public void setKategorie(Kategorie kategorie) {
		this.kategorie = kategorie;
	}
	/* (non-Javadoc)
	 * @see com.inffem.dbif.BookIf#getRating()
	 */
	public Rating getRating() {
		return rating;
	}
	/* (non-Javadoc)
	 * @see com.inffem.dbif.BookIf#setRating(int)
	 */
	public void setRating(Rating rating) {
		this.rating = rating;
	}
	
	@Override
	public boolean equals(Object arg0) {
		if( !(arg0 instanceof BookImpl )) { return false ; }
		BookImpl other = (BookImpl) arg0; 
		if(other.autor.equals(autor) 
				&& other.titel.equals(titel)
				&& other.nachname.equals(nachname)
				&& other.vorname.equals(vorname)) {
			return true;
		}
		return false;
	}

	@Override
	public int hashCode() {
		return  autor.hashCode() + titel.hashCode(); 
	}
	
	@Override
	public String toString() {
		StringBuilder s = new StringBuilder();	
		s.append(nachname);
		s.append(autor);
		s.append(";");
		s.append(titel);
		s.append(";");
		s.append(kategorie);
		s.append(";");
		s.append(rating);
		s.append(";");
		s.append(vorname);
		return s.toString();
	}
}
